#include <iostream>
#include "yunba_server.h"
#include <unistd.h>

int extendedCmdArrive(void *context, EXTED_CMD cmd, int status, int ret_string_len, char *ret_string)
{
    return 0;
    //处理接收到的扩展命令返回。
}

int messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
{
    int i;
    char *payloadptr;
    Presence_msg my_present;
    int ret =get_present_info(topicName,m,&my_present);
    printf("     len:%d\n",m->payloadlen);
    printf("      message: ");

    payloadptr=(char *)m->payload;
    *(payloadptr+m->payloadlen)='\0';
    printf("%s",payloadptr);
    putchar('\n');

    MQTTClient_freeMessage(&m);
    // MQTTClient_freeMessage(topicName);
    return ret;
    //处理topic以及推送的消息内容。
}

int main() {
    yunba_server test1(messageArrived,extendedCmdArrive);
    test1.setup();
    test1.connect();

    while(1)
    {
        sleep(2);
    }
    return 0;

}